{include file="public/layout" /}
<body>
<div class="layui-fluid" id="LAY-component-layer-list">
    <div class="layui-row">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="web-system">
                    <div class="layui-tab layui-tab-card">
                        {include file="system/bar" /}
                        <div class="layui-tab-content" style="padding:10px 0">
                            <div class="layui-tab-item layui-show">
                                <div class="layui-row layui-col-space15">
                                    <div class="layui-col-md12">
                                        <div class="layui-card">
                                            <div class="layui-card-body" pad15>
                                                <div class="layui-form" wid100 lay-filter="">
                                                    <div class="layui-form-item layadmin-layer-demo">
                                                        <label class="layui-form-label">短信配置</label>
                                                        <div class="layui-input-inline">
                                                            <button class="layui-btn layui-btn-sm" id="sms_tpl_list">短信模板</button>
                                                        </div>
                                                    </div>
                                                    <div class="layui-form-item">
                                                        <label class="layui-form-label"><b>*</b>选择短信平台</label>
                                                        <div class="layui-input-inline">
                                                            <select name="sms_platform" id="sms_platform">
                                                                <option value="1" {if condition="isset($config.sms_platform) && $config.sms_platform eq 1"}selected="selected"{/if}>阿里云短信</option>
                                                            </select>
                                                        </div>
                                                    </div>


                                                    <div class="layui-form-item">
                                                        <label class="layui-form-label"><b>*</b>短信平台[appkey]</label>
                                                        <div class="layui-input-inline">
                                                            <input id="sms_appkey" name="sms_appkey"  lay-verify="required" value="{$config.sms_appkey|default=''}" class="layui-input" type="text"/>
                                                        </div>
                                                        <div class="layui-form-mid layui-word-aux ey_helptips"></div>
                                                        <div class="layui-form-inline2 ey_helptips_txt">短信平台配置appkey/keyid</div>
                                                    </div>

                                                    <div class="layui-form-item">
                                                        <label class="layui-form-label"><b>*</b>短信平台[secretKey]</label>
                                                        <div class="layui-input-inline">
                                                            <input id="sms_secretkey" name="sms_secretkey"  lay-verify="required" value="{$config.sms_secretkey|default=''}" class="layui-input" type="text"/>
                                                        </div>
                                                        <div class="layui-form-mid layui-word-aux ey_helptips"></div>
                                                        <div class="layui-form-inline2 ey_helptips_txt">短信平台配置secretKey</div>
                                                    </div>
                                                    <div class="layui-form-item">
                                                        <label class="layui-form-label">公司名/品牌名/产品名</label>
                                                        <div class="layui-input-inline">
                                                            <input id="sms_product" name="sms_product" value="{$config.sms_product|default=''}" class="layui-input" type="text"/>
                                                        </div>
                                                        <div class="layui-form-mid layui-word-aux ey_helptips"></div>
                                                        <div class="layui-form-inline2 ey_helptips_txt">公司名/品牌名/产品名</div>
                                                    </div>
                                                    <div class="layui-form-item">
                                                        <label class="layui-form-label"><b>*</b>短信码超时时间</label>
                                                        <div class="layui-input-inline">
                                                            <select id="sms_time_out" name="sms_time_out">
                                                                <option value="60" {if condition="isset($config.sms_time_out) && $config.sms_time_out eq 60"}selected="selected"{/if}>1分钟</option>
                                                                <option value="120"{if condition="isset($config.sms_time_out) && $config.sms_time_out eq 120"}selected="selected"{/if}>2分钟</option>
                                                                <option value="300"{if condition="isset($config.sms_time_out) && $config.sms_time_out eq 300"}selected="selected"{/if}>5分钟</option>
                                                                <option value="600"{if condition="isset($config.sms_time_out) && $config.sms_time_out eq 600"}selected="selected"{/if}>10分钟</option>
                                                                <option value="1200"{if condition="isset($config.sms_time_out) && $config.sms_time_out eq 1200"}selected="selected"{/if}>20分钟</option>
                                                                <option value="1800"{if condition="isset($config.sms_time_out) && $config.sms_time_out eq 1800"}selected="selected"{/if}>30分钟</option>
                                                            </select>
                                                        </div>
                                                        <div class="layui-form-mid layui-word-aux ey_helptips"></div>
                                                        <div class="layui-form-inline2 ey_helptips_txt">发送短信验证码间隔时间</div>
                                                    </div>
                                                    <div class="layui-form-item">
                                                        <label class="layui-form-label"><b>*</b>测试接收的手机号码</label>
                                                        <div class="layui-input-inline">
                                                            <input value="{$config.sms_test_mobile|default=''}" name="sms_test_mobile" id="sms_test_mobile" class="layui-input" type="text">
                                                        </div>
                                                        <div class="layui-input-inline">
                                                            <button class="layui-btn layui-btn-sm" lay-submit lay-filter="sendMobile">发送</button>
                                                        </div>
                                                    </div>
                                                    <div class="layui-form-item">
                                                        <div class="layui-input-block">
                                                            <button class="layui-btn" lay-submit lay-filter="formSubmit">确认提交</button>
                                                        </div>
                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <script type="text/javascript">
        layui.config({
            base: '__SKIN__/' //静态资源所在路径
            ,version: '{$version}'
        }).extend({
            index: 'lib/index' //主入口模块
        }).use(['index', 'form'], function(){
            var $ = layui.$
                ,layer = layui.layer
                ,form = layui.form;

            $('#sms_tpl_list').click(function(){
                var iframes = layer.open({
                    type: 2,
                    title: '短信模板',
                    fixed: true, //不固定
                    shadeClose: false,
                    shade: 0.3,
                    area: ['800px', '400px'],
                    content: "{:url('System/sms_tpl')}"
                });
            });

            form.on('submit(sendMobile)', function(data){
                if (data.field.sms_test_mobile == '') {
                    showErrorMsg('测试手机号码不能为空！');
                    $('input[name=sms_test_mobile]').focus();
                    return false;
                } else {
                    var that = this;
                    var load = layer_loading();
                    var txt = $(that).html();
                    $(that).html('发送中…');
                    data.field._ajax = 1;
                    $.ajax({
                        type: "post",
                        data: data.field,
                        dataType: 'json',
                        url: "{:url('System/send_mobile')}",
                        success: function (res) {
                            layer.close(load);
                            $(that).html(txt);
                            if (res.code == 1) {
                                layer.msg('发送成功', {icon: 1, time:1000});
                            } else {
                                showErrorMsg(res.msg);
                            }
                        },
                        error: function(){
                            layer.close(load);
                            $(that).html(txt);
                            showErrorAlert('发送超时！');
                        }
                    })
                }
                return false;
            });

            //监听提交
            form.on('submit(formSubmit)', function(data){
                var load = layer_loading();
                data.field._ajax = 1;
                $.ajax({
                    type : 'post',
                    url : "{:url('System/sms')}",
                    data : data.field,
                    dataType : 'json',
                    success : function(res){
                        layer.close(load); //关闭loading
                        if(res.code == 1){
                            layer.msg(res.msg, {icon: 1, time: 1000}, function(){
                                window.location.reload();
                            });
                        }else{
                            if (res.data.icon && res.data.icon == 4) {
                                layer.alert(res.msg, {icon: res.data.icon, title: false, closeBtn: false}, function(){
                                    window.location.reload();
                                });
                            } else {
                                showErrorMsg(res.msg);
                            }
                        }
                    },
                    error: function(e){
                        layer.close(load); //关闭loading
                        showErrorAlert();
                    }
                });
                return false;
            });

        });
    </script>

    {include file="public/footer" /}
